package com.sds.replicator.servlets;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import javax.servlet.http.HttpServletRequest;

@Singleton
public class FacebookReplicator extends FetcherServlet {

    public static String LOCAL_PATH = "/fb";

    @Inject
    public FacebookReplicator() {
        super(LOCAL_PATH, "http://www.facebook.com/");
    }

    @Override
    protected String transformURL(String targetURL, HttpServletRequest incomingRequest) {
        if (targetURL != null) {
            if (targetURL.contains("login.php")) {
                targetURL = targetURL.replace("https://www.facebook.com/login.php?login_attempt=1", "https://www.facebook.com/login.php?m=m&refsrc=http%3A%2F%2Fwww.facebook.com%2F");
            } else {
                targetURL = targetURL.replace("m.facebook.com", "www.facebook.com");
            }
        }
        return super.transformURL(targetURL, incomingRequest);
    }
}
